#include <func.h>

#define MAXLINE 256

int main(int argc, char* argv[])
{
	// 关联两根管道
	int writefd = open("pipe1", O_WRONLY);
	if (writefd == -1) {
		error(1, errno, "open pipe1");
	}

	int readfd = open("pipe2", O_RDONLY); // 阻塞点
	if (readfd == -1) {
		error(1, errno, "open pipe2");
	}


	printf("Conenection Established\n");

	for(;;) {
		char message[MAXLINE];
		// 从键盘读入消息
		fgets(message, MAXLINE, stdin);
		// 写入管道1
		write(writefd, message, strlen(message));
		// 读管道2
		char buf[MAXLINE];
		read(readfd, buf, MAXLINE);
		// 将管道2中的数据输出到stdout
		printf("received from p1: %s", buf);
	}

	return 0;
}














